<?php
if(!isset($dbselect)) //前面没设置 数据库 则指定使用 DB3
    $dbselect   = Db::G3();
///关于标收费信息的统计
$sfwhere      = "";
if($startdate!="" && $enddate!=""){
  $sfwhere    = " and qtime_h>='$startdate' and  qtime_h<='$enddate'";  
} 
$rows = $dbselect->GetRows("SELECT 
sum(if(flowty='diyafeiincome',-money,0)) as 押金转利润, sum(if(flowty='diyafeiincome',1,0))as 押金转利润次数,
b.cid,SUBSTR( qtime_h, 1, 10 ) as qtime_h
FROM  `04a_5flow_cid` f  left join 05b_0base b on f.busid =b.bid 
WHERE  `flowty` in ('diyafeiincome') and atnm='cid_yajin' $sfwhere
group by b.cid,SUBSTR( qtime_h, 1, 10 )");
foreach($rows as &$row){
    $cid    = $row['cid'];
    $ctime  = strtotime($row['qtime_h']);
    $Y      = date("Y", $ctime);
    $M      = date("n", $ctime);
    $D      = date("j", $ctime); 
    //$c_ya   = $row['押金次数'];
 
    $c_b_c  = $row['押金转利润次数'];
    
    ///对于标一些特殊的资金变动的特殊统计 
    
    if($c_b_c>0){
        CTLog::G()->doctAndDayReal($c_b_c.",rp_{$Y}{$m}_st01",1,"tot_yajinlr",$row['押金转利润'],$Y,$M,$D); //逾期还款罚息利润
        CTLog::G()->doctAndDayReal($c_b_c.",rp_{$Y}{$m}_cid",$cid,"tot_yajinlr",$row['押金转利润'],$Y,$M,$D);
    }
}

$rows = $dbselect->GetRows("SELECT 
sum(if(flowty='zhongjiefh',money,0)) as 中介费, sum(if(flowty='zhongjiefh',1,0))as 中介费次数,
b.cid,SUBSTR( qtime_h, 1, 10 ) as qtime_h
FROM  `04a_5flow_cid` f  left join 05b_0base b on f.busid =b.bid 
WHERE  atnm='cid_jinzijin' and atnm2='cid_zjf' and `flowty` in ('zhongjiefh') $sfwhere
group by b.cid,SUBSTR( qtime_h, 1, 10 )");
foreach($rows as &$row){
    $cid    = $row['cid'];
    $ctime  = strtotime($row['qtime_h']);
    $Y      = date("Y", $ctime);
    $M      = date("n", $ctime);
    $D      = date("j", $ctime); 
    $c_b_zj = $row['中介费次数'];    
    if($c_b_zj>0){
        CTLog::G()->doctAndDayReal($c_b_zj.",rp_{$Y}{$m}_st01",1,"tot_b_zjf_lr",$row['中介费'],$Y,$M,$D);  
        CTLog::G()->doctAndDayReal($c_b_zj.",rp_{$Y}{$m}_cid",$cid,"tot_b_zjf_lr",$row['中介费'],$Y,$M,$D);
    }
}